package com.scalar.chiptrack.commons.bean;

import java.util.HashMap;
import java.sql.Timestamp;

/**
 * User: Ganesh
  * Date: Apr 29, 2008
  * Time: 11:25:58 AM
 */

public class RowResultBeanImpl implements IRowResultBean {
    HashMap dbRow;

    public RowResultBeanImpl(HashMap dbRow)
    {
        this.dbRow = dbRow;
    }

    /**
     * Get the value of the given search column
     * @return String
     */
    public String getValue(String columnName)throws Exception
    {
        String s = "";
        try
        {
            if (this.dbRow != null)
            {
                s = (String)dbRow.get(columnName);
            }

        }
        catch(Exception e)
        {
            e.printStackTrace();
            throw new Exception("Error occreed in Search Row Bean implementation");
        }
        return s;
    }


    /**
     * Get the value of an id column. This will currently return a string representing the id in decimal.
     * We can later add a hexadecimal API.
     * @return String
     */
    public String getId(String columnName)throws Exception
    {
        String value = null;
        try
        {
            value = getValue(columnName);
        }
        catch(Exception e)
        {
            e.printStackTrace();
            throw new Exception("Error occreed in Search Row Bean implementation");
        }
        return value;
    }

    /**
     * Gets the value as a timestamp. This will be useful in case we want to format the timestamp
     * according to a format key, for a particular locale.
     * Usage <bean:write name="beanName" property="timestampValue[columnName]" formatKey="mile.prompt.for.format"/>
     * @return Timestamp
     */
    public Timestamp getTimestampValue(String columnName)throws Exception
    {
        Timestamp t = null;
        try
        {
            if (dbRow != null);
               // t = _dbRow.getTimestamp(columnName);
        }
        catch(Exception e)
        {
            e.printStackTrace();
            throw new Exception("Error occured in Search Row bean implementation");
        }
        return t;
    }
    /**
     * Gets the value as a Double. This will be usefule in case we want to fromat the timestamp
     * according to a format key, for a particular locale.
     * @return Double
     */
    public double getDoubleValue(String columnName)throws Exception
    {
        double d = 0.0d;
        try
        {
            if (dbRow != null);
                //d = _dbRow.getDouble(columnName);
        }
        catch(Exception e)
        {
            e.printStackTrace();
            throw new Exception("Error occured in Search Row Bean implementation");
        }
        return d;
    }
}
